package com.zcl.Thread.t18;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @Description:
 * @author: zcl
 * @date: 2022/3/11  10:53
 */
public class ExecutorsDemo {
    /**
     * <!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
     * <dependency>
     *     <groupId>com.google.guava</groupId>
     *     <artifactId>guava</artifactId>
     *     <version>31.1-jre</version>
     * </dependency>
     */

    //    private static ThreadFactory namedThreadFactory = new ThreadFactoryBuilder()
//    private static ThreadPoolExecutor executor = new ThreadPoolExecutor(
//            10,
//            15,
//            10,
//            TimeUnit.SECONDS,
//            new LinkedBlockingQueue<>(),
//            new ThreadFactoryBuilder().setNameFormat("guava-%d").build(),
//            new ThreadPoolExecutor.DiscardPolicy()
//    );

    private static ThreadPoolExecutor executor = new ThreadPoolExecutor(
            10,
            15,
            10,
            TimeUnit.SECONDS,
            new LinkedBlockingQueue<>(),
            new ThreadFactory() {
                @Override
                public Thread newThread(Runnable r) {
                    return newThread(r);
                }
            },
            new ThreadPoolExecutor.DiscardPolicy()
    );

    public static void main(String[] args) {
        executor.execute(new Runnable() {
            @Override
            public void run() {

            }
        });
    }
}
